import React, { ReactNode } from 'react';
import { Redirect } from 'umi';
import { IUserDataState } from '@/models/models';

interface IAuth {
  children: ReactNode;
}

const Auth: React.FC<IAuth> = (props) => {
  const user: IUserDataState | null = JSON.parse(localStorage.getItem('user')!);
  if (user?.token || user?.userId) {
    return <div>{props.children}</div>;
  } else {
    return <Redirect to="/login" />;
  }
};

export default Auth;
